
(function () { 
	Lhs.ui.CreateSettingWindow = function () {
	var pathimage=Ti.App.Properties.getString('pathimage');
	var platformWidth=Titanium.Platform.displayCaps.platformWidth;//Ti.App.Properties.getInt('platformWidth');
	var platformHeight=Titanium.Platform.displayCaps.platformHeight;//Ti.App.Properties.getInt('platformHeight');
    var win = Titanium.UI.createWindow({
        id: 'Setting',
        title: 'Setting',
        fullscreen: true,
        backgroundImage: pathimage+'setting.png',
        navBarHidden:true,
        orientationModes:[
	        Titanium.UI.LANDSCAPE_LEFT,
	        Titanium.UI.LANDSCAPE_RIGHT,
		]
      
    });
    /*
    var egc = new globals.EventGarbageCollection(win);
    egc.addEventListener('back_'+win.id, function () {
    	Lhs.navGroup.close(win, {
             animated: true
        });
    	
	});
	*/
	var btnumber_width=(platformWidth-70)/3;
	var btnumber_height=(platformHeight-70)/2;
	
	var bottom_row1=(platformHeight-40)/2;
	var bottom_row2=20;
	
	
	var top_row1=20;
	var top_row2=20+btnumber_height;
	var left_col1=35;
	var left_col2=35+btnumber_width;
	var left_col3=35+2*btnumber_width;
	var views=[
		{id:1,title:'CA LÀM VIỆC',func:Lhs.ui.CreateTableWindow,backgroundImage:pathimage+'setting11.png',backgroundSelectedImage:pathimage+'setting11.png',bottom:bottom_row1,left:left_col1},
		{id:2,title:'POS',func:Lhs.ui.CreateTableWindow,backgroundImage:pathimage+'setting2.png',backgroundSelectedImage:pathimage+'setting2.png',bottom:bottom_row1,left:left_col2},
		{id:3,title:'CASH DRAWER',func:Lhs.ui.CreateTableWindow,backgroundImage:pathimage+'setting3.png',backgroundSelectedImage:pathimage+'setting1.png',bottom:bottom_row1,left:left_col3},
		{id:4,title:'BÁO CÁO',func:Lhs.ui.CreateTableWindow,backgroundImage:pathimage+'setting4.png',backgroundSelectedImage:pathimage+'setting1.png',bottom:bottom_row2,left:left_col1},
		{id:5,title:'QUẢN LÝ',func:Lhs.ui.CreateManagementWindow,backgroundImage:pathimage+'setting5.png',backgroundSelectedImage:pathimage+'setting1.png',bottom:bottom_row2,left:left_col2},
		{id:6,title:'ĐĂNG XUẤT',func:Lhs.ui.CreateTableWindow,backgroundImage:pathimage+'setting6.png',backgroundSelectedImage:pathimage+'setting1.png',bottom:bottom_row2,left:left_col3},
	]
	
	
	var createButton = function (bt) {
		var bt = Titanium.UI.createButton({
			// color:'Red',
			// title:bt.title,
		 	// borderColor: '#c0c0c0',
		   //  borderRadius: 10,
		    // borderWidth:4,
		     id:bt.id,
			 func:bt.func,
			 backgroundImage:bt.backgroundImage,
			// backgroundSelectedImage:bt.backgroundSelectedImage,
			 width:btnumber_width,
			 height:btnumber_height,
		   	 //top:bt.top,
		   	 bottom:bt.bottom,
		   	 left:bt.left,
	   	 	 font:{
				fontSize:Ti.App.Properties.getInt('MainWindow_btnumber_fontsize'),
				fontWeight:'bold',
			 },
		}); 
		bt.addEventListener('click', function (e) {
			require('settings').ClickSound();
			/*
			var iconWin  =e.source.func();
            Lhs.navGroup.open(iconWin, {
                animated: true
            });
            */
           //Ti.API.info (e.source.id)
            if(e.source.id==2)
            {
            	var iconWin  =e.source.func();
	            Lhs.navGroup.open(iconWin, {
	                animated: true
	            });
            }
            else if(e.source.id==5)
            {
            	var iconWin  =e.source.func();
	            Lhs.navGroup.open(iconWin, {
	                animated: true
	            });
            }
            else if(e.source.id==6)
            {
            	Lhs.navGroup.close(win, {
		             animated: true
		        });
            }
            else
            {
            	require('settings').createAlertDialog(Ti.App.Properties.getString('title'),'Chức năng đang được xây dựng.\nVui lòng quay lại sau.');
            }
            
            
        })
		return bt;
	}
	for (i = 0; i < views.length; i++){
		
        var btadd=createButton(views[i])
		win.add(btadd);
		
    }
	
	
	// removing the event listener does
	win.addEventListener('close', function() {
		//Ti.App.removeEventListener('bad:idea');
	});
	
	
 	return win;
       
    };
})();